home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / lib / mntc6846.zoo / patch / xnorm4.s < prev    next >
Encoding:
Text File  |  1994-11-26  |  2.5 KB  |  96 lines

  1.  ! C68 4-byte-floating point normalization routine
  2.  !-----------------------------------------------------------------------------
  3.  ! ported to 68000 by Kai-Uwe Bloem, 12/89
  4.  !  #1  original author: Peter S. Housel
  5.  !  #2    added support for denormalized numbers            -kub-, 01/90
  6.  !  #3  Changed entry point name for C68 comaptibility, and
  7.  !    changed error handling code.                -djw-    09/93
  8.  !-----------------------------------------------------------------------------
  9.  
  10.     .sect .text
  11.  
  12.     .define .Xnorm4
  13.  
  14. !-----------------------------------------------
  15. ! on entry to .Xnorm4:
  16. !    D0.w    exponent of result
  17. !    D2.w    sign byte in left most bit position
  18. !        sticky bit in least significant byte
  19. !    D1.b    rounding bits
  20. !    A1    mantissa pointer
  21. !-----------------------------------------------
  22.  
  23. .Xnorm4:
  24.     movem.l    d3-d5,-(sp)    ! save some registers
  25.  
  26.     move.l    (a1),d4        ! rounding and u.mant == 0 ?
  27.     bne    0f
  28.     tst.b    d1
  29.     beq    retz
  30. 0:
  31.     clr.b    d2        ! "sticky byte"
  32.     move.l    #0xff000000,d5
  33. 1:    tst.w    d0        ! divide (shift)
  34.     ble    0f        !  denormalized number
  35. 9:    move.l    d4,d3
  36.     and.l    d5,d3        !  or until no bits above 23
  37.     beq    2f
  38. 0:    add.w    #1,d0        ! increment exponent
  39.     lsr.l    #1,d4
  40.     or.b    d1,d2        ! set "sticky"
  41.     bra    9b
  42. 2:
  43.     and.b    #1,d2
  44.     or.b    d2,d1        ! make least sig bit "sticky"
  45.     move.l    #0xff800000,d5
  46. 3:    move.l    d4,d3        ! multiply (shift) until
  47.     and.l    d5,d3        ! one in "implied" position
  48.     bne    4f
  49.     sub.w    #1,d0        ! decrement exponent
  50.     beq    4f        !  too small. store as denormalized number
  51.     add.b    d1,d1        ! some doubt about this one *
  52.     addx.l    d4,d4
  53.     bra    3b
  54. 4:
  55.     tst.b    d1        ! check rounding bits
  56.     bge    6f        ! round down - no action neccessary
  57.     neg.b    d1
  58.     bvc    5f        ! round up
  59.     btst    #0,d4        ! tie case - use state of last bit
  60.     beq    0f        ! .. no rounding needed
  61. 5:
  62.     clr.w    d1        ! zero rounding bits
  63.     add.l    #1,d4
  64.     tst.w    d0
  65.     bne    0f        ! renormalize if number was denormalized
  66.     add.w    #1,d0        ! correct exponent for denormalized numbers
  67.     bra    1b
  68. 0:    move.l    d4,d3        ! check for rounding overflow
  69.     and.l    #0xff000000,d3
  70.     bne    1b        ! go back and renormalize
  71. 6:
  72.     tst.l    d4        ! check if normalization caused an underflow
  73.     beq    retz
  74.     cmp.w    #0,d0        ! check for exponent overflow or underflow
  75.     blt    retz
  76.     cmp.w    #255,d0
  77.     bge    oflow
  78.  
  79.     lsl.w    #7,d0        ! re-position exponent
  80.     and.w    #0x8000,d2    ! sign bit
  81.     or.w    d2,d0
  82.     swap    d0        ! map to upper word
  83.     clr.w    d0
  84.     and.l    #0x7fffff,d4    ! top mantissa bits
  85.     or.l    d0,d4        ! insert exponent and sign
  86.     move.l    d4,(a1)
  87. finish:    movem.l    (sp)+,d3-d5
  88.     rts
  89.  
  90. retz:    clr.l    (a1)
  91.     bra    finish
  92.  
  93. oflow:    jsr    .overflow    ! call routine to raise FP exception
  94.     move.l    d0,(a1)        ! return made - set return value
  95.     bra    finish
  96.